home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 26 / CU Amiga Magazine's Super CD-ROM 26 (1998)(EMAP Images)(GB)[!][issue 1998-09].iso / CUCD / Utilities / MegaBook / Rexx / LoadOld.mbrx < prev    next >
Text File  |  1998-07-15  |  2KB  |  106 lines

  1. /*
  2. ** LoadOld.mbrx Version 1.1
  3. ** By Tom Bampton
  4. **
  5. ** © 1996,1998 Eden Developments
  6. **
  7. ** Loads an old MegaBook v2.0/2.1 file.
  8. ** If you wish to convert files, its probably better to use the FileConvert
  9. ** programs instead of this script. This is just an example! Interestingly
  10. ** enuff, this is an almost direct conversion of the C code used in
  11. ** MegaBook v2.0/2.1 to load files. 
  12. **
  13. ** If you run this from the CLI with RX then you can give it a filename
  14. ** argument. If an argument isn't found, you'll get a file requester.
  15. **
  16. ** From MegaBook v3.1, this script may also be used from the menu option
  17. ** 'Load Old...'
  18. **
  19. ** MegaBook 4.0 has a loader built in for all MegaBook formats now, so this
  20. ** is pretty pointless except as an example.
  21. */
  22.  
  23. /* The path to MegaBook in case it isn't running */
  24. MegaBookPath = 'MegaBook:MegaBook'
  25.  
  26. /* To get newlines in requesters */
  27. LF = '0a'x
  28.  
  29. parse arg File
  30.  
  31. /* Check if MegaBook is running, if not, run it */
  32. if ~show('P', 'MEGABOOK.01') then do
  33.     address command
  34.     'run >nil: ' MegaBookPath
  35.     /* Wait for the ARexx port */
  36.     do 5 while ~show('P', 'MEGABOOK.01')
  37.         'sys:rexxc/waitforport MEGABOOK.01'
  38.     end
  39. end
  40.  
  41. address 'MEGABOOK.01'
  42. options results
  43.  
  44. /* If no command line arguments, open the file requester */
  45. if File = '' then do
  46.     SelectFile 'Select MegaBook v2.0 file ...'
  47.     File = result
  48.     if RC = 5 then exit
  49. end
  50.  
  51. if Open(fp, File, 'r') then do
  52.     
  53.     head = readln(fp)
  54.     
  55.     /* Check the header for the filetype */
  56.     if head ~= 'PB20' then do
  57.         Request 'Not a MegaBook 2.0/2.1 file' GADS 'Sorry'
  58.         call Close(fp)
  59.         exit
  60.     end
  61.     
  62.     /* Remove the current database */
  63.     GetNumRecs
  64.     if rc ~= 0 then do
  65.         
  66.         Request 'You will lose your current database'LF'Are you sure ?' Gads '_Yes|_No'
  67.         if RC = 1 then New No_Confirm
  68.         else exit
  69.     end
  70.     
  71.     do while ~eof(fp)
  72.         
  73.         /* Read name, fone number and fax numeber */
  74.         name = readln(fp)
  75.          
  76.         if(eof(fp)) then break
  77.         
  78.         fone = readln(fp)
  79.         fax = readln(fp)
  80.         
  81.         /* Add an entry */
  82.         Add_Entry
  83.         /* Put in the name */
  84.         Put_Entry 1 name
  85.         /* Blank out the unneeded fields */
  86.         Put_Entry 2 ''
  87.         Put_Entry 3 ''
  88.         Put_Entry 4 ''
  89.         Put_Entry 5 ''
  90.         Put_Entry 6 ''
  91.         /* And store the fone number and fax */
  92.         Put_Entry 7 fone
  93.         Put_Entry 8 fax
  94.         Set_Type 1 1
  95.         Set_Type 2 2
  96.                 
  97.     end
  98.     
  99.     call Close(fp)
  100.     end
  101.     
  102. else do
  103.     /* We couldn't open the requsted file, display an error */
  104.     Request 'Cant find file' GADS 'Sorry'
  105. end
  106.